Skip to content

feat(ud): Phase 2, 3 and 4#1663

Merged
Tobbe merged 30 commits intomainfrom
tobbe-feat-ud-support-phase-2
Apr 29, 2026
Merged

feat(ud): Phase 2, 3 and 4#1663
Tobbe merged 30 commits intomainfrom
tobbe-feat-ud-support-phase-2

Conversation

@Tobbe
Copy link
Copy Markdown
Member

@Tobbe Tobbe commented Apr 22, 2026

I keep working towards universal-deploy support. To keep things runnable and verifiable this PR introduces a few temporary constructs that will be removed as we make progress. They're all clearly marked in both the overall plan document and in the code.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 22, 2026

Deploy Preview for cedarjs ready!

Name Link
🔨 Latest commit e1a0645
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/69f29284d002750008a9a8c7
😎 Deploy Preview https://deploy-preview-1663--cedarjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

Greptile Summary

Implements Phases 2–4 of Universal Deploy integration: buildCedarDispatcher / createCedarFetchable in @cedarjs/api-server, cedarUniversalDeployPlugin + buildUDApiServer in @cedarjs/vite, cedar serve api --ud CLI opt-in, and a fully-implemented (not yet wired) cedarDevDispatcherPlugin for the future single-port dev server. Issues from previous reviews (ESM cache-busting, race condition in the dev dispatcher, isApiRequest prefix matching, Windows path separators, apiAvailablePort regression in devHandler) are all addressed in this revision.

Confidence Score: 5/5

Safe to merge; only P2 findings remain.

All previous P1 findings are resolved. Two P2 findings remain: a doc misattribution of buildUDApiServer and an unconditional UD Vite build step that adds latency to all API builds. Neither blocks correctness.

docs/implementation-docs/2026-03-26-cedarjs-project-overview.md (api-server row) and packages/cli/src/commands/build/buildHandler.ts (unconditional UD build task)

Important Files Changed

Filename Overview
packages/api-server/src/udDispatcher.ts New dispatcher: discovers API functions via fast-glob, builds a rou3 router, handles ESM cache-busting, GraphQL special-casing, and proper error handling. Previously-flagged issues (extension stripping, ALL_HTTP_METHODS for non-GraphQL, cacheBust token) are all correctly implemented.
packages/api-server/src/udFetchable.ts Thin wrapper that calls buildCedarContext and delegates to a CedarHandler. Simple and correct.
packages/vite/src/plugins/vite-plugin-cedar-dev-dispatcher.ts Fully implemented but not yet wired in (Phase 5 work). Previous race-condition, isApiRequest prefix-matching, Windows path separator, and ESM cache issues are all resolved via generation counter, path.sep, and cacheBust token.
packages/vite/src/plugins/vite-plugin-cedar-universal-deploy.ts Registers virtual:cedar-api with UD store and resolves virtual:ud:catch-all to Cedar's aggregate Fetchable. Clean Vite plugin implementation.
packages/vite/src/buildUDApiServer.ts Orchestrates the Vite SSR build for the UD Node entry; correctly comments that "ssr" here means server-side module build, not Cedar HTML SSR.
packages/cli/src/commands/build/buildHandler.ts Adds unconditional UD Vite build step to every cedar build api, regardless of --ud usage; adds build time for all users not just UD adopters.
packages/cli/src/commands/dev/devHandler.ts Adds --ud flag to cedar dev; fixes the previously-flagged apiAvailablePort=undefined regression for serverFile path (line 70 now correctly defaults to apiPreferredPort).
packages/cli/src/commands/serve.ts Adds --ud flag to cedar serve api; forks the Vite-built api/dist/ud/index.js entry with proper error handling and env forwarding.
docs/implementation-docs/2026-03-26-cedarjs-project-overview.md Updated for Phase 4 UD work; api-server row incorrectly attributes buildUDApiServer (which lives in @cedarjs/vite) to itself.

Reviews (22): Last reviewed commit: "make phase 4 vs phase 5 more clear" | Re-trigger Greptile

Comment thread packages/api-server/src/createUDServer.ts Outdated
Comment thread packages/api-server/src/createUDServer.ts
Comment thread packages/api-server/src/createUDServer.ts
Comment thread packages/api-server/src/createUDServer.ts
Comment thread yarn.lock Outdated
Comment thread packages/graphql-server/src/types.ts
@github-actions github-actions Bot added this to the next-release milestone Apr 22, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 22, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit e1a0645

Command Status Duration Result
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 4m 27s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 1m 14s View ↗
nx run-many -t build ✅ Succeeded 3m 26s View ↗
nx run-many -t test:types ✅ Succeeded 11s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-29 23:37:33 UTC

@Tobbe Tobbe changed the title feat(ud): Phase 2 feat(ud): Phase 2 and 3 Apr 22, 2026
@Tobbe
Copy link
Copy Markdown
Member Author

Tobbe commented Apr 22, 2026

@greptileai you said "This PR adds Phase 2 of the Universal Deploy integration". What's left to do for Phase 3, to also be able to include that in this PR?

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

According to the implementation plan, Phase 3's exit criteria are:

  1. Cedar can run in production on Node without Fastify — the createUDServer (srvx-based) covers this for the standalone UD server, but the plan specifically calls for @universal-deploy/adapter-node to be the mechanism, not a custom srvx server.

  2. Cedar's server entries registered in the UD store at build time — the Vite plugin does call addEntry(), but the virtual module it returns is a 501 stub:

    // vite-plugin-cedar-universal-deploy.ts
    return new Response(
      'Cedar API virtual entry: not yet implemented (Phase 5)',
      { status: 501 },
    )

    This needs to be replaced with a real Fetchable that dispatches to the discovered Cedar API functions.

  3. yarn cedar serve no longer depends on Fastify — not addressed yet.

So concretely, what's left:

  • Replace the 501 stub in vite-plugin-cedar-universal-deploy.ts's load() with a real Cedar API dispatcher. The route discovery logic already exists in createUDServer.ts — the pieces are there, they just need to be wired into the virtual module's fetch handler.
  • Validate @universal-deploy/adapter-node end-to-end (the plan calls this out explicitly as a Phase 3 deliverable).
  • Wire yarn cedar serve to delegate to the UD node adapter rather than Fastify.

The plan notes that Phase 3's real Fetchable implementation depends on the Phase 2 route manifest — which is partly why the PR punted it to Phase 5. But since Phase 2 route discovery is also in this PR (createUDServer handles it at runtime), you have enough to at least make the virtual module non-stub and do the end-to-end validation.

Comment thread packages/api-server/src/udDispatcher.ts Outdated
@Tobbe Tobbe changed the title feat(ud): Phase 2 and 3 feat(ud): Phase 2, 3 and 4 Apr 23, 2026
Comment thread packages/vite/src/plugins/vite-plugin-cedar-dev-dispatcher.ts
Comment thread packages/vite/src/plugins/vite-plugin-cedar-dev-dispatcher.ts Outdated
Comment thread packages/vite/src/plugins/vite-plugin-cedar-dev-dispatcher.ts
Comment thread packages/vite/src/plugins/vite-plugin-cedar-dev-dispatcher.ts
Comment thread packages/cli/src/commands/dev/devHandler.ts
Comment thread packages/cli/src/commands/dev/devHandler.ts Outdated
@Tobbe Tobbe merged commit 61e7f54 into main Apr 29, 2026
44 checks passed
@Tobbe Tobbe deleted the tobbe-feat-ud-support-phase-2 branch April 29, 2026 23:45
Tobbe added a commit that referenced this pull request Apr 29, 2026
@github-actions
Copy link
Copy Markdown

The changes in this PR are now available on npm.

Try them out by running yarn cedar upgrade -t 4.0.0-canary.13870

Or try it in a new app with yarn dlx create-cedar-app@4.0.0-canary.13870

@Tobbe Tobbe modified the milestones: next-release, v4.1.0 Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant